﻿using System;
using NazTek.Extension.Clr4.Test;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace NazTek.Extension.Clr4.Test
{
    /// <summary>
    /// Contains Unit Tests for IntExtension class public members
    /// </summary>
    [TestClass()]
    public class IntExtensionTest
    {
        private TestContext testContextInstance;
        /// <summary>
        /// Gets/Sets current test context, e.g., property bag
        /// </summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }
        /// <summary>
        /// Attempt to convert a int to a specific class type, should return null
        /// </summary>
        [TestMethod()]
        [ExpectedException(typeof(CustomException))]
        public void TestToEnum_Class()
        {
            10.ToEnum<MockPerson>();
        }
        /// <summary>
        /// Attempt to convert a int to an enum type whose underlying type is int, should return the corresponding item
        ///</summary>
        [TestMethod()]
        public void TestToEnum_Defined()
        {
            Assert.AreEqual<Enum>(MockGender.Female, Convert.ToInt32(MockGender.Female).ToEnum<MockGender>());
        }
        /// <summary>
        /// Attempt to convert a int to an enum type in which the value is not defined, should return null
        /// </summary>
        [TestMethod()]
        [ExpectedException(typeof(CustomException))]
        public void TestToEnum_Undefined()
        {
            10.ToEnum<MockGender>();
        }
        /// <summary>
        /// Attempt to convert an int to an enum type whose underlying type is byte but the value is undefined, with the exception flag on, should raise an exception
        /// </summary>
        [TestMethod()]
        [ExpectedException(typeof(CustomException))]
        public void TestToEnum_TypeMismatchWithException()
        {
            int iValueOfEnum = 10;
            iValueOfEnum.ToEnum<MockSalutation>();
        }
    }
}
